// lib/components/StatusTag.dart
import 'package:flutter/material.dart';

class StatusTag extends StatelessWidget {
  final num status;
  final List tagList;
  final double fontSize;
  final EdgeInsetsGeometry padding;
  final double borderRadius;

  const StatusTag({
    Key? key,
    required this.status,
    required this.tagList,
    this.fontSize = 12,
    this.padding = const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
    this.borderRadius = 4,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 转换status为整数以便使用List索引
    int statusIndex = status.toInt();
    
    // 确保索引有效，否则使用默认值
    if (statusIndex < 0 || statusIndex >= tagList.length || tagList[statusIndex] == null) {
      statusIndex = 0; // 默认使用第一个元素或空对象
    }
    
    // 如果tagList[statusIndex]是空的或不存在，提供默认值
    final tagData = statusIndex > 0 && statusIndex < tagList.length
        ? tagList[statusIndex]
        : {'title': '未知', 'bgcolor': Colors.grey, 'color': Colors.white};

    return Container(
      padding: padding,
      decoration: BoxDecoration(
        color: tagData['bgcolor'],
        borderRadius: BorderRadius.circular(borderRadius),
      ),
      child: Text(
        tagData['title'] ?? '',
        style: TextStyle(
          fontSize: fontSize,
          color: tagData['color'],
        ),
      ),
    );
  }
}